package engine.gui;

import engine.game.Game;
import engine.game.Manager;
import engine.graphics.Color4f;
import engine.graphics.FontManager;
import engine.gui.events.EventMethod;

public abstract class MenuScreen extends ParentObject{

	private static final long serialVersionUID = 1L;

	public static final String BACKGROUND_PANEL_NAME = "background"; 
	
	private final Game game ; 
	private Panel mainScreen ; 
	
	public MenuScreen(Manager m, Game g, int x, int y, int w, int h) {
		super(m, x, y, w, h);
		this.game = g ; 
		init();
	}

	public Game getGame(){
		return this.game ; 
	}

	public void init(){
		super.init();
		this.changeNormalColor(new Color4f(1.0f, 1.0f, 1.0f, 0.0f));
		this.disableClicking(); 
		this.disableHovering();  
		this.addNewChild(BACKGROUND_PANEL_NAME, getNewDefaultPanel(this));
		this.mainScreen = getNewDefaultPanel(this); 
		this.addNewChild("mainScreen", mainScreen);
	}
	
	public void render(){
		super.render(); 
	}
	
	public abstract void addNewButton(String caption, EventMethod event); 
	public abstract void addNewButton(Panel screen, String caption, EventMethod event); 
	
	
	public void addCaptionToScreen(String caption){
		this.addCaptionToScreen(this.getMainScreen(), caption);
	}
	
	public void addCaptionToScreen(Panel screen, String caption){
		Label lCaption = new Label(this.getManager(), this, caption) ; 
		lCaption.setFontName(FontManager.S_FONT_20);
		int w = screen.getObjectWidth(); 
		lCaption.padding((w-(caption.length()*FontManager.getFontByName(FontManager.S_FONT_20).getFont().getSize()/3*2))/2, -20);  
		screen.addNewChild("caption", lCaption);
	}
	
	public Panel getBackgroundPanel(){
		return (Panel)this.getChildByName(BACKGROUND_PANEL_NAME);
	}
	
	public Panel getMainScreen(){
		return this.mainScreen; 
	}
	
	public static Panel getNewDefaultPanel(MenuScreen menu){
		Panel panel = new Panel(menu.getManager(), menu, menu.getObjectWidth(), menu.getObjectHeight());
		panel.enableTexturing() ; 
		panel.changeNormalColor(new Color4f(1.0f, 1.0f, 1.0f, 0.0f));
		return panel ; 
	}
}
